home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / DBMSOTPT.SQL < prev    next >
Encoding:
Text File  |  1995-05-09  |  8.6 KB  |  186 lines

  1. rem 
  2. rem $Header: dbmsotpt.sql 7020100.1 94/09/23 22:14:37 cli Generic<base> $ 
  3. rem 
  4. Rem  Copyright (c) 1991 by Oracle Corporation 
  5. Rem    NAME
  6. Rem      dbmsotpt.sql - used by sql*dba 'set serveroutput on' cmd
  7. Rem    DESCRIPTION
  8. Rem    NOTES
  9. Rem      SQL*DBA and SQL*PLUS depend on this package.
  10. Rem    RETURNS
  11. Rem 
  12. Rem    MODIFIED   (MM/DD/YY)
  13. Rem     wmaimone   07/08/94 -  216381 fix comments
  14. Rem     adowning   03/29/94 -  merge changes from branch 1.9.710.1
  15. Rem     adowning   02/02/94 -  split file into public / private binary files
  16. Rem     rkooi      04/20/93 -  merge changes from branch 1.8.312.1 
  17. Rem     rkooi      01/20/93 -  up default to 20000 
  18. Rem     rkooi      11/27/92 -  change error handling overflow case 
  19. Rem     rkooi      10/09/92 -  add some comments 
  20. Rem     rkooi      10/08/92 -  change newline to new_line 
  21. Rem     rkooi      09/29/92 -  more comments 
  22. Rem     rkooi      09/28/92 -  change some comments 
  23. Rem     rkooi      09/26/92 -  Creation 
  24.  
  25. Rem This script must be run as user SYS.
  26.  
  27. create or replace package dbms_output as
  28.  
  29.   ------------
  30.   --  OVERVIEW
  31.   --
  32.   --  These procedures accumulate information in a buffer (via "put" and
  33.   --  "put_line") so that it can be retrieved out later (via "get_line" or
  34.   --  "get_lines").  If this package is disabled then all
  35.   --  calls to this package are simply ignored.  This way, these routines
  36.   --  are only active when the client is one that is able to deal with the
  37.   --  information.  This is good for debugging, or SP's that want to want
  38.   --  to display messages or reports to sql*dba or plus (like 'describing
  39.   --  procedures', etc.).  The default buffer size is 20000 bytes.  The 
  40.   --  minimum is 2000 and the maximum is 1,000,000.
  41.  
  42.   -----------
  43.   --  EXAMPLE
  44.   --
  45.   --  A trigger might want to print out some debugging information.  To do
  46.   --  do this the trigger would do 
  47.   --    dbms_output.put_line('I got here:'||:new.col||' is the new value');
  48.   --  If the client had enabled the dbms_output package then this put_line
  49.   --  would be buffered and the client could, after executing the statement
  50.   --  (presumably some insert, delete or update that caused the trigger to
  51.   --  fire) execute
  52.   --    begin dbms_output.get_line(:buffer, :status); end;
  53.   --  to get the line of information back.  It could then display the
  54.   --  buffer on the screen.  The client would repeat calls to get_line
  55.   --  until status came back as non-zero.  For better performance, the
  56.   --  client would use calls to get_lines which can return an array of
  57.   --  lines.
  58.   --
  59.   --  SQL*DBA and SQL*PLUS, for instance, implement a 'SET SERVEROUTPUT
  60.   --  ON' command so that they know whether to make calls to get_line(s)
  61.   --  after issuing insert, update, delete or anonymous PL/SQL calls 
  62.   --  (these are the only ones that can cause triggers or stored procedures
  63.   --  to be executed).
  64.  
  65.   ------------
  66.   --  SECURITY
  67.   --
  68.   --  At the end of this script, a public synonym (dbms_output) is created
  69.   --  and execute permission on this package is granted to public.
  70.  
  71.   ----------------------------
  72.   --  PROCEDURES AND FUNCTIONS
  73.   --
  74.   procedure enable (buffer_size in integer default 20000);
  75.   --  Enable calls to put, put_line, new_line, get_line and get_lines.
  76.   --    Calls to these procedures are noops if the package has
  77.   --    not been enabled.  Set default amount of information to buffer.
  78.   --    Cleanup data buffered from any dead sessions.  Multiple calls to
  79.   --    enable are allowed.
  80.   --  Input parameters:
  81.   --    buffer_size
  82.   --      Amount of information, in bytes, to buffer.  Varchar2, number and
  83.   --      date items are stored in their internal representation.  The 
  84.   --      information is stored in the SGA. An error is raised if the 
  85.   --      buffer size is exceeded.  If there are multiple calls to enable,
  86.   --      then the buffer_size is generally the largest of the values
  87.   --      specified, and will always be >= than the smallest value
  88.   --      specified.  Currently a more accurate determination is not
  89.   --      possible.  The maximum size is 1,000,000, the minimum is 2000.
  90.  
  91.   procedure disable;
  92.   --  Disable calls to put, put_line, new_line, get_line and get_lines.
  93.   --    Also purge the buffer of any remaining information.
  94.  
  95.   procedure put(a varchar2);
  96.   procedure put(a number);
  97.   procedure put(a date);
  98.   --  Put a piece of information in the buffer.  When retrieved by
  99.   --    get_line(s), the number and date items will be formated with
  100.   --    to_char using the default formats.  If you want another format
  101.   --    then format it explicitly and use the put(<varchar2>) call.
  102.   --    Note that this routine is overloaded on the type of its argument.
  103.   --    The proper version will be used depending on argument type.
  104.   --  Input parameters:
  105.   --    a
  106.   --      Item to buffer
  107.  
  108.   procedure put_line(a varchar2);
  109.   procedure put_line(a number);
  110.   procedure put_line(a date);
  111.   --  Put a piece of information in the buffer followed by an end-of-line
  112.   --    marker.  When retrieved by get_line(s), the number and date items
  113.   --    will be formated with to_char using the default formats.  If you
  114.   --    want another format then format it explicitly and use the
  115.   --    put_line(<varchar2>) call.  Note that this routine is overloaded on
  116.   --    the type of its argument.  The proper version will be used depending
  117.   --    on argument type.  get_line(s) return "lines" as delimited by
  118.   --    "newlines".  So every call to put_line or new_line will generate a
  119.   --    line that will be returned by get_line(s).
  120.   --  Input parameters:
  121.   --    a
  122.   --      Item to buffer
  123.   --  Errors raised:
  124.   --    -20000, ORU-10027: buffer overflow, limit of <buf_limit> bytes.
  125.   --    -20000, ORU-10028: line length overflow, limit of 255 bytes per line.
  126.  
  127.   procedure new_line;
  128.   --  Put an end-of-line marker.  get_line(s) return "lines" as delimited
  129.   --    by "newlines".  So every call to put_line or new_line will generate
  130.   --    a line that will be returned by get_line(s).
  131.   --  Errors raised:
  132.   --    -20000, ORU-10027: buffer overflow, limit of <buf_limit> bytes.
  133.   --    -20000, ORU-10028: line length overflow, limit of 255 bytes per line.
  134.  
  135.   procedure get_line(line out varchar2, status out integer);
  136.   --  Get a single line back that has been buffered.  The lines are
  137.   --    delimited by calls to put_line or new_line.  The line will be
  138.   --    constructed taking all the items up to a newline, converting all 
  139.   --    the items to varchar2, and concatenating them into a single line.
  140.   --    If the client fails to retrieve all lines before the next put,
  141.   --    put_line or new_line, the non-retrieved lines will be discarded.
  142.   --    This is so if the client is interrupted while selecting back 
  143.   --    the information, there will not be junk left over which would 
  144.   --    look like it was part of the NEXT set of lines.
  145.   --  Output parameters:
  146.   --    line
  147.   --      This line will hold the line - it may be up to 255 bytes long.
  148.   --    status
  149.   --      This will be 0 upon successful completion of the call.  1 means
  150.   --      that there are no more lines.
  151.  
  152.   type chararr is table of varchar2(255) index by binary_integer;
  153.   procedure get_lines(lines out chararr, numlines in out integer);
  154.   --  Get multiple lines back that have been buffered.  The lines are
  155.   --    delimited by calls to put_line or new_line.  The line will be
  156.   --    constructed taking all the items up to a newline, converting all 
  157.   --    the items to varchar2, and concatenating them into a single line.
  158.   --    Once get_lines is executed, the client should continue to retrieve
  159.   --    all lines because the next put, put_line or new_line will first
  160.   --    purge the buffer of leftover data.  This is so if the client is
  161.   --    interrupted while selecting back the information, there will not
  162.   --    be junk left over.
  163.   --  Input parameters:
  164.   --    numlines
  165.   --      This is the maximum number of lines that the caller is prepared
  166.   --      to accept.  This procedure will not return more than this number
  167.   --      of lines.
  168.   --  Output parameters:
  169.   --    lines
  170.   --      This array will line will hold the lines - they may be up to 255
  171.   --      bytes long each.  The array is indexed beginning with 0 and
  172.   --      increases sequentially.  From a 3GL host program the array begins
  173.   --      with whatever is the convention for that language.
  174.   --    numlines
  175.   --      This will be the number of lines actually returned.  If it is
  176.   --      less than the value passed in, then there are no more lines.
  177. end;
  178. /
  179.  
  180. drop public synonym dbms_output
  181. /
  182. create public synonym dbms_output for dbms_output
  183. /
  184. grant execute on dbms_output to public
  185. /
  186.